﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using OSharp.Core;
using OSharp.Core.Modules;
using OSharp.Entity;
using OSharp.Filter;
using Starzero.Framework.Systems.Dtos;
using Starzero.Framework.Systems.Entities;
using Starzero.Framework.Web.Areas.Admin.Controllers;
using Starzero.Plugins.RevitApp;
using Starzero.Plugins.RevitApp.Entities;

namespace Starzero.Framework.Web.Areas.Business.Controllers.Example
{
    [ModuleInfo(Order = 3, Position = "Example", PositionName = "示例模块")]
    [Description("业务-示例信息")]
    public class ExampleController : BusinessApiController
    {
        private readonly IExampleContract _exampleContract;

        /// <summary>
        /// 初始化一个<see cref="ExampleController"/>类型的新实例
        /// </summary>
        public ExampleController(IExampleContract exampleContract)
        {
            _exampleContract = exampleContract;
        }

        /// <summary>
        /// 读取数据审计信息列表
        /// </summary>
        /// <param name="request">页请求</param>
        /// <returns></returns>
        [HttpPost]
        [ModuleInfo]
        [Description("读取")]
        [Logined]
        public PageData<ExampleOutputDto> Read(PageRequest request)
        {
            Expression<Func<Plugins.RevitApp.Entities.Example, bool>> predicate = FilterHelper.GetExpression<Plugins.RevitApp.Entities.Example>(request.FilterGroup);
            PageResult<ExampleOutputDto> page;
            request.AddDefaultSortCondition(new SortCondition("CreatedTime", ListSortDirection.Descending));
            page = _exampleContract.Examples.ToPage(predicate, request.PageCondition, m => new ExampleOutputDto
            {
                Title = m.Title,
                Content = m.Content,
                CreatedTime = m.CreatedTime
            });
            return page.ToPageData();
        }
    }
}
